package inet.app.view.activity;

import inet.app.R;
import inet.app.common.XoSoConstants;
import inet.app.controller.connect.MasterConnector;
import inet.app.controller.parser.Parser_Kqxs;
import inet.app.controller.parser.Parser_Push_MB;
import inet.app.controller.request.Request;
import inet.app.model.cau.CauCell;
import inet.app.model.cau.CauPosition;
import inet.app.model.cau.KetQua;
import inet.app.model.lottery.GetLoto;
import inet.app.model.lottery.LotteryResult;
import inet.app.model.object.KqGiai_Item;
import inet.app.model.util.ProgressDialog;
import inet.app.model.util.StringTool;
import inet.app.model.util.Util;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Iterator;
import android.app.Dialog;
import android.content.Intent;
import android.graphics.Color;
import android.os.AsyncTask;
import android.os.Bundle;
import android.text.Html;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.format.Time;
import android.text.style.ForegroundColorSpan;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class CauNgayDetail extends BaseFragmentActivity implements OnClickListener{
	private int posGiai,posPartGiai,posOfAll,start, myYear, myMonth, myDay, myHour, myMinute,countclick=0,biendo=5, cauNumber;
	private String code,listnumber="",date,nhamang="",trunggiai="",kqDe="",mangKQ,mangLo,response,name,strKqSoi="",strLoto = "",
			rngay=null,rthang=null,rgiaidb=null,rgiai1=null,rgiai2=null,rgiai3=null,rgiai4=null,rgiai5=null,rgiai6=null,rgiai7=null,rgiai8=null;
	private String giaidb, giai1,giai2_0,giai2_1,giai3_0,giai3_1,giai3_2,giai3_3,giai3_4,giai3_5,giai4_0,giai4_1
	,giai4_2,giai4_3,giai4_4,giai4_5,giai4_6,giai5_0,giai5_1,giai5_2,giai5_3,giai5_4,giai5_5,giai6_0,giai6_1,giai6_2,giai7_0,giai7_1,giai7_2,giai7_3;
	String [] giai2,giai3,giai4,giai5,giai6,giai7;
	
	private WebView webView;
	private boolean isTrung=false,dangnghe=false;
	private Dialog dialog;
	private ProgressDialog pdia;
	private ArrayList<String> listaudio = new ArrayList<String>();
	private Button bt_ThongKe;
	private Request request = new Request();
	private ArrayList<KqGiai_Item> arraylist = new ArrayList<KqGiai_Item>();
	private String [] listKQ,data[],databuf[];
	private LotteryResult lotteryresult;
	private ArrayList<String> list = new ArrayList<String>();
    public static CauCell cauCell;
    public static ArrayList<KetQua> ketQuaList;
    private ArrayList<CauPosition> cauPosList;
	private MasterConnector master;
	private TextView tvChiTietPt;
		@Override
		public void onCreate(Bundle savedInstanceState) {
			// TODO Auto-generated method stub
			super.onCreate(savedInstanceState);
			setContentView(R.layout.caungay_detail);
			pdia= new ProgressDialog(CauNgayDetail.this);
			getData();
			initBase();
			initScreen();
		}
		private void getData() {
			// TODO Auto-generated method stub
			Intent intent = getIntent();
		    biendo = intent.getIntExtra("biendo", 1);
		    code = intent.getStringExtra("code");
		    name = intent.getStringExtra("tentinh");
		    list = intent.getStringArrayListExtra("list");
		    response = intent.getStringExtra("response");
		    cauNumber = intent.getIntExtra("cauNumber", 1);
		  //----------------------------------GET POSITION CAU ------------------
			 if(cauCell!=null){
		    	  cauPosList = new ArrayList<CauPosition>();
		    	  CauPosition cP1 = Util.getCauPosition(cauCell.position1);
		    	  cauPosList.add(cP1);
		    	  CauPosition cP2 = Util.getCauPosition(cauCell.position2);
		    	  cauPosList.add(cP2);
		    	  int a = cP1.giaiIndex;
		      }
		}
		private void initScreen() {
			// TODO Auto-generated method stub
			master = new MasterConnector(((MyApp) getApplication()).get_socket());
			bt_ThongKe = (Button) findViewById(R.id.bt_ThongKe);
			webView = (WebView) findViewById(R.id.webView);
			tvChiTietPt = (TextView) findViewById(R.id.tvChiTietPt);
//			tvChiTietPt.setText("Chi tiết phân tích kết quả " + biendo + " ngày của Xổ Số " + name +" dự đoán cho cặp số " 
//			+ Util.BongCouple(cauNumber)+ " ra trong lần quay tới" +"\nVị trí ghép lên phân tích >> Vị trí 1 : " + cauCell.position1+", Vị trí 2 : " +cauCell.position2);
			String p1 = "Chi tiết phân tích kết quả ";
			String p2 = ""+biendo;
			String p3 = " ngày của Xổ Số ";
			String p4= name;
			String p5 =" dự đoán cho cặp số ";
			String p6= Util.BongCouple(cauNumber);
			String p7 = " ra trong lần quay tới" +"\nVị trí ghép lên phân tích >> Vị trí 1 : ";
			String p8 = ""+cauCell.position1;
			String p9= ", Vị trí 2 : ";
			String p10 = ""+cauCell.position2;
			
			
			Spannable span = new SpannableString("Chi tiết phân tích kết quả " + biendo + " ngày của Xổ Số " + name +" dự đoán cho cặp số " 
					+ Util.BongCouple(cauNumber)+ " ra trong lần quay tới" +"\nVị trí ghép lên phân tích >> Vị trí 1 : " + cauCell.position1+", Vị trí 2 : " +cauCell.position2);
			span.setSpan(new ForegroundColorSpan(Color.RED), p1.length(), p1.length()+p2.length(),Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
			span.setSpan(new ForegroundColorSpan(Color.RED), p1.length()+p2.length()+p3.length(), p1.length()+p2.length()+p3.length()+p4.length(),Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
			span.setSpan(new ForegroundColorSpan(Color.RED), p1.length()+p2.length()+p3.length()+p4.length()+p5.length(), p1.length()+p2.length()+p3.length()+p4.length()+p5.length()+p6.length(),Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
			span.setSpan(new ForegroundColorSpan(Color.RED), p1.length()+p2.length()+p3.length()+p4.length()+p5.length()+p6.length()+p7.length(), p1.length()+p2.length()+p3.length()+p4.length()+p5.length()+p6.length()+p7.length()+p8.length(),Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
			span.setSpan(new ForegroundColorSpan(Color.RED), p1.length()+p2.length()+p3.length()+p4.length()+p5.length()+p6.length()+p7.length()+p8.length()+p9.length(), p1.length()+p2.length()+p3.length()+p4.length()+p5.length()+p6.length()+p7.length()+p8.length()+p9.length()+p10.length(),Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
			
			tvChiTietPt.setText(span);
			
			//Set day, month, year
			Time time = new Time();
			time.setToNow();
			final Calendar cal = Calendar.getInstance();
			myYear = cal.get(Calendar.YEAR);
			myMonth = cal.get(Calendar.MONTH) + 1;
			myDay = cal.get(Calendar.DATE);
			// SET DATE CURRENT
			Calendar c = Calendar.getInstance();
			SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
			SimpleDateFormat df2 = new SimpleDateFormat("HH:mm");
			String timecurren= df2.format(c.getTime());
			//END SET TIME
			
			webView.setWebViewClient(new MyWebViewClient());
			webView.getSettings().setJavaScriptEnabled(true);
			webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
			webView.getSettings().setPluginsEnabled(true);
			webView.getSettings().setSupportMultipleWindows(true);
			webView.getSettings().setSupportZoom(false);
			webView.setVerticalScrollBarEnabled(true);
			webView.setHorizontalScrollBarEnabled(false);
		       
			//---------------------------------SEND REQUEST-----------------------
			ParserData(code, response);
		}

		public void ParserData(final String code, final String response) {
			pdia.show();
			AsyncTask<Void, Integer, Void> myTask = new AsyncTask<Void, Integer, Void>() {
			protected Void doInBackground(Void... params) {
				// TODO Auto-generated method stub
				Parser_Push_MB  parser = new Parser_Push_MB();
				arraylist = parser.getList_Cau(response);
				return null;
			}
			protected void onPostExecute(Void result) {
				super.onPreExecute();
				if (arraylist!=null) {
					String strBong = null;
					if (code.equals("XSTD")){ 
						strBong = getChuoiSoiCau(arraylist).replaceAll(" ","");
						Load_data_webview_mb(arraylist,strBong);
					}else{
						strBong = getChuoiSoiCauTn(arraylist).replaceAll(" ","");
						Load_data_webview_tn(arraylist,strBong);
					}
					pdia.dismiss();
				}else {
					webView.clearCache(true);
					webView.loadDataWithBaseURL(null, "","text/html", "utf-8", null);
					pdia.dismiss();
					Util.showDialog(1, CauNgayDetail.this);
				}
			}
		};
		myTask.execute();
		}
		
		private String getChuoiSoiCau(ArrayList<KqGiai_Item> arraylist){
			for (int i = 0; i < arraylist.size(); i++) {
				if (arraylist.get(i).getGiaidb().equals(""))
					giaidb = ".....";
				else
					giaidb = arraylist.get(i).getGiaidb();
				if (arraylist.get(i).getGiai1().equals(""))
					giai1 = ".....";
				else
					giai1 = arraylist.get(i).getGiai1();

				giai2 = (arraylist.get(i).getGiai2()).split("-");
				giai3 = (arraylist.get(i).getGiai3()).split("-");
				giai4 = (arraylist.get(i).getGiai4()).split("-");
				giai5 = (arraylist.get(i).getGiai5()).split("-");
				giai6 = (arraylist.get(i).getGiai6()).split("-");
				giai7 = (arraylist.get(i).getGiai7()).split("-");
				
				giai2_0= giai2[0];
				giai2_1= giai2[1].replaceAll(" ", "");
				giai3_0= giai3[0].replaceAll(" ", "");
				giai3_1= giai3[1].replaceAll(" ", "");
				giai3_2= giai3[2].replaceAll(" ", "");
				giai3_3= giai3[3].replaceAll(" ", "");
				giai3_4= giai3[4].replaceAll(" ", "");
				giai3_5= giai3[5].replaceAll(" ", "");
				
				giai4_0= giai4[0].replaceAll(" ", "");
				giai4_1= giai4[1].replaceAll(" ", "");
				giai4_2= giai4[2].replaceAll(" ", "");
				giai4_3= giai4[3].replaceAll(" ", "");
				
				giai5_0= giai5[0].replaceAll(" ", "");
				giai5_1= giai5[1].replaceAll(" ", "");
				giai5_2= giai5[2].replaceAll(" ", "");
				giai5_3= giai5[3].replaceAll(" ", "");
				giai5_4= giai5[4].replaceAll(" ", "");
				giai5_5= giai5[5].replaceAll(" ", "");
				
				giai6_0= giai6[0].replaceAll(" ", "");
				giai6_1= giai6[1].replaceAll(" ", "");
				giai6_2= giai6[2].replaceAll(" ", "");
				
				giai7_0= giai7[0].replaceAll(" ", "");
				giai7_1= giai7[1].replaceAll(" ", "");
				giai7_2= giai7[2].replaceAll(" ", "");
				giai7_3= giai7[3].replaceAll(" ", "");
				// DANH DAU VI TRI 
				for (int j = 0; j < 2; j++) {
					 posGiai= cauPosList.get(j).giaiIndex;
			    	 posPartGiai = cauPosList.get(j).posIndex;
			    	 posOfAll= cauPosList.get(j).posOfAll;
					switch (posOfAll) {
					case 1:
						strKqSoi+= ""+giaidb.charAt(posPartGiai);
						break;
					case 2:
						strKqSoi+= ""+giai1.charAt(posPartGiai);
						break;
					case 3:
						strKqSoi+= ""+giai2_0.charAt(posPartGiai);
						break;
					case 4:
						strKqSoi+= ""+giai2_1.charAt(posPartGiai);
						break;
					case 5:
						strKqSoi+= ""+giai3_0.charAt(posPartGiai);
						break;
					case 6:
						strKqSoi+= ""+giai3_1.charAt(posPartGiai);
						break;
					case 7:
						strKqSoi+= ""+giai3_2.charAt(posPartGiai);
						break;
					case 8:
						strKqSoi+= ""+giai3_3.charAt(posPartGiai);
						break;
					case 9:
						strKqSoi+= ""+giai3_4.charAt(posPartGiai);
						break;
					case 10:
						strKqSoi+= ""+giai3_5.charAt(posPartGiai);
						break;
					case 11:
						strKqSoi+= ""+giai4_0.charAt(posPartGiai);
						break;
					case 12:
						strKqSoi+= ""+giai4_1.charAt(posPartGiai);
						break;
					case 13:
						strKqSoi+= ""+giai4_2.charAt(posPartGiai);
						break;
					case 14:
						strKqSoi+= ""+giai4_3.charAt(posPartGiai);
						break;
					case 15:
						strKqSoi+= ""+giai5_0.charAt(posPartGiai);
						break;
					case 16:
						strKqSoi+= ""+giai5_1.charAt(posPartGiai);
						break;
					case 17:
						strKqSoi+= ""+giai5_2.charAt(posPartGiai);
						break;
					case 18:
						strKqSoi+= ""+giai5_3.charAt(posPartGiai);
						break;
					case 19:
						strKqSoi+= ""+giai5_4.charAt(posPartGiai);
						break;
					case 20:
						strKqSoi+= ""+giai5_5.charAt(posPartGiai);
						break;
					case 21:
						strKqSoi+= ""+giai6_0.charAt(posPartGiai);
						break;
					case 22:
						strKqSoi+= ""+giai6_1.charAt(posPartGiai);
						break;
					case 23:
						strKqSoi+= ""+giai6_2.charAt(posPartGiai);
						break;
					case 24:
						strKqSoi+= ""+giai7_0.charAt(posPartGiai);
						break;
					case 25:
						strKqSoi+= ""+giai7_1.charAt(posPartGiai);
						break;
					case 26:
						strKqSoi+= ""+giai7_2.charAt(posPartGiai);
						break;
					case 27:
						strKqSoi+= ""+giai7_3.charAt(posPartGiai);
						break;
					default:
						break;
					}
				}
			}
			System.out.println( "KET QUA SOI LÀ : =================>> " +strKqSoi);
			return strKqSoi;
		}
		private String getChuoiSoiCauTn(ArrayList<KqGiai_Item> arraylist){
		String htmlKetqua = "", htmlfooter = "",giaidb,giai1,giai2,giai5,giai7,giai8;
		String [] giai3,giai4,giai6;
		
		for (int i = 0; i < arraylist.size(); i++) {
		//Get dãy Loto
		lotteryresult = new LotteryResult(arraylist.get(i).getGiaidb(), arraylist.get(i).getGiai1(), arraylist.get(i).getGiai2(),
				arraylist.get(i).getGiai3(), arraylist.get(i).getGiai4(),arraylist.get(i).getGiai5(),arraylist.get(i).getGiai6(),arraylist.get(i).getGiai7(),arraylist.get(i).getGiai8());
		GetLoto getloto = new GetLoto();
		String numberfirts, numberend;
		@SuppressWarnings("unchecked")
		Collection<String> cEndNumbers = getloto.getEndNumberOfLotteryResult(lotteryresult, 2);
		for (Iterator<String> it = cEndNumbers.iterator(); it.hasNext();) {
			strLoto += it.next() + ", ";
		}
		//End day loto
		
		giaidb = arraylist.get(i).getGiaidb();
		giai1 = arraylist.get(i).getGiai1();
		giai2 = arraylist.get(i).getGiai2();
		giai3 = arraylist.get(i).getGiai3().split("-");
		giai4 = arraylist.get(i).getGiai4().split("-");
		giai5 = arraylist.get(i).getGiai5();
		giai6 = arraylist.get(i).getGiai6().split("-");
		giai7 = arraylist.get(i).getGiai7();
		giai8 = arraylist.get(i).getGiai8();
		
		giai3_0 = giai3[0].replaceAll(" ", "");
		giai3_1 = giai3[1].replaceAll(" ", "");
		
		giai4_0= giai4[0].replaceAll(" ", "");
		giai4_1= giai4[1].replaceAll(" ", "");
		giai4_2= giai4[2].replaceAll(" ", "");
		giai4_3= giai4[3].replaceAll(" ", "");
		giai4_4= giai4[4].replaceAll(" ", "");
		giai4_5= giai4[5].replaceAll(" ", "");
		giai4_6= giai4[6].replaceAll(" ", "");
		
		giai6_0= giai6[0].replaceAll(" ", "");
		giai6_1= giai6[1].replaceAll(" ", "");
		giai6_2= giai6[2].replaceAll(" ", "");
		
		// DANH DAU VI TRI 
		for (int j = 0; j < 2; j++) {
			 posGiai= cauPosList.get(j).giaiIndex;
	    	 posPartGiai = cauPosList.get(j).posIndex;
	    	 posOfAll= cauPosList.get(j).posOfAll;
			switch (posOfAll) {
			case 1:
				strKqSoi+= ""+giaidb.charAt(posPartGiai);
				break;
			case 2:
				strKqSoi+= ""+giai1.charAt(posPartGiai);
				break;
			case 3:
				strKqSoi+= ""+giai2.charAt(posPartGiai);
				break;
			case 4:
				strKqSoi+= ""+giai3_0.charAt(posPartGiai);
				break;
			case 5:
				strKqSoi+= ""+giai3_1.charAt(posPartGiai);
				break;
			case 6:
				strKqSoi+= ""+giai4_0.charAt(posPartGiai);
				break;
			case 7:
				strKqSoi+= ""+giai4_1.charAt(posPartGiai);
				break;
			case 8:
				strKqSoi+= ""+giai4_2.charAt(posPartGiai);
				break;
			case 9:
				strKqSoi+= ""+giai4_3.charAt(posPartGiai);
				break;
			case 10:
				strKqSoi+= ""+giai4_4.charAt(posPartGiai);
				break;
			case 11:
				strKqSoi+= ""+giai4_5.charAt(posPartGiai);
				break;
			case 12:
				strKqSoi+= ""+giai4_6.charAt(posPartGiai);
				break;
			case 13:
				strKqSoi+= ""+giai5.charAt(posPartGiai);
				break;
			case 14:
				strKqSoi+= ""+giai6_0.charAt(posPartGiai);
				break;
			case 15:
				strKqSoi+= ""+giai6_1.charAt(posPartGiai);
				
				break;
			case 16:
				strKqSoi+= ""+giai6_2.charAt(posPartGiai);
				break;
			case 17:
				strKqSoi+= ""+giai7.charAt(posPartGiai);
				break;
			case 18:
				strKqSoi+= ""+giai8.charAt(posPartGiai);
				break;
			default:
				break;
			}
			}
		}
		return strKqSoi;
		}
		private void Load_data_webview_mb(ArrayList<KqGiai_Item> arraylist,String bong) {
			// TODO Auto-generated method stub
			String htmlKetqua = "",htmtSendSms="";
			String buttonSms = "";
			
			//PARSER BONG 
			ArrayList<String> arr_bong = new ArrayList<String>();
			for (int i = 0; i < bong.length()/2; i++) {
				arr_bong.add(""+bong.substring(i*2,(i+1)*2));
			}
			arr_bong.add("");
			//END PARSER BONG
			
			for (int i = 0; i < arraylist.size(); i++) {
				//Get dãy Loto
				strLoto="";
				lotteryresult = new LotteryResult(arraylist.get(i).getGiaidb(), arraylist.get(i).getGiai1(), arraylist.get(i).getGiai2(),
						arraylist.get(i).getGiai3(), arraylist.get(i).getGiai4(),arraylist.get(i).getGiai5(),arraylist.get(i).getGiai6(),arraylist.get(i).getGiai7());
				GetLoto getloto = new GetLoto();
				String numberfirts, numberend;
				@SuppressWarnings("unchecked")
				Collection<String> cEndNumbers = getloto.getEndNumberOfLotteryResult(lotteryresult, 2);
				for (Iterator<String> it = cEndNumbers.iterator(); it.hasNext();) {
					strLoto += it.next() + ", ";
				}
				
				strLoto = (strLoto.replaceAll(arr_bong.get(i+1) + "", "<span style=\'color:red;\'>"
						+ arr_bong.get(i+1) + "</span>").replaceAll(Util.Inverse(arr_bong.get(i+1)) + "", "<span style=\'color:red;\'>"
								+ Util.Inverse(arr_bong.get(i+1)) + "</span>"));
				//End day loto
			if (arraylist.get(i).getGiaidb().equals(""))
				giaidb = ".....";
			else
				giaidb = arraylist.get(i).getGiaidb();
			if (arraylist.get(i).getGiai1().equals(""))
				giai1 = ".....";
			else
				giai1 = arraylist.get(i).getGiai1();

			giai2 = (arraylist.get(i).getGiai2()).split("-");
			giai3 = (arraylist.get(i).getGiai3()).split("-");
			giai4 = (arraylist.get(i).getGiai4()).split("-");
			giai5 = (arraylist.get(i).getGiai5()).split("-");
			giai6 = (arraylist.get(i).getGiai6()).split("-");
			giai7 = (arraylist.get(i).getGiai7()).split("-");
			
			giai2_0= giai2[0].replaceAll(" ", "");
			giai2_1= giai2[1].replaceAll(" ", "");
			giai3_0= giai3[0].replaceAll(" ", "");
			giai3_1= giai3[1].replaceAll(" ", "");
			giai3_2= giai3[2].replaceAll(" ", "");
			giai3_3= giai3[3].replaceAll(" ", "");
			giai3_4= giai3[4].replaceAll(" ", "");
			giai3_5= giai3[5].replaceAll(" ", "");
			
			giai4_0= giai4[0].replaceAll(" ", "");
			giai4_1= giai4[1].replaceAll(" ", "");
			giai4_2= giai4[2].replaceAll(" ", "");
			giai4_3= giai4[3].replaceAll(" ", "");
			
			giai5_0= giai5[0].replaceAll(" ", "");
			giai5_1= giai5[1].replaceAll(" ", "");
			giai5_2= giai5[2].replaceAll(" ", "");
			giai5_3= giai5[3].replaceAll(" ", "");
			giai5_4= giai5[4].replaceAll(" ", "");
			giai5_5= giai5[5].replaceAll(" ", "");
			
			giai6_0= giai6[0].replaceAll(" ", "");
			giai6_1= giai6[1].replaceAll(" ", "");
			giai6_2= giai6[2].replaceAll(" ", "");
			
			giai7_0= giai7[0].replaceAll(" ", "");
			giai7_1= giai7[1].replaceAll(" ", "");
			giai7_2= giai7[2].replaceAll(" ", "");
			giai7_3= giai7[3].replaceAll(" ", "");
			// DANH DAU VI TRI 
			for (int j = 0; j < 2; j++) {
				 posGiai= cauPosList.get(j).giaiIndex;
		    	 posPartGiai = cauPosList.get(j).posIndex;
		    	 posOfAll= cauPosList.get(j).posOfAll;
				switch (posOfAll) {
				case 1:
					strKqSoi+= ""+giaidb.charAt(posPartGiai);
					giaidb = giaidb.substring(0,posPartGiai)+ "<span style=\'color:#00CC99; font-size:20px; font-weight :bold ;\'>"
							+ giaidb.charAt(posPartGiai) + "</span>"+giaidb.substring(posPartGiai+1, giaidb.length());
					break;
				case 2:
					strKqSoi+= ""+giai1.charAt(posPartGiai);
					giai1 = giai1.substring(0,posPartGiai)+ "<span style=\'color:#00CC99; font-size:20px; font-weight :bold ;\'>"
							+ giai1.charAt(posPartGiai) + "</span>"+giai1.substring(posPartGiai+1, giai1.length());
					break;
				case 3:
					strKqSoi+= ""+giai2_0.charAt(posPartGiai);
					giai2_0 = giai2_0.substring(0,posPartGiai)+ "<span style=\'color:#00CC99; font-size:20px; font-weight :bold ;\'>"
							+ giai2_0.charAt(posPartGiai) + "</span>"+giai2_0.substring(posPartGiai+1, giai2_0.length());
					break;
				case 4:
					strKqSoi+= ""+giai2_1.charAt(posPartGiai);
					giai2_1 = giai2_1.substring(0,posPartGiai)+ "<span style=\'color:#00CC99; font-size:20px; font-weight :bold ;\'>"
							+ giai2_1.charAt(posPartGiai) + "</span>"+giai2_1.substring(posPartGiai+1, giai2_1.length());
					break;
				case 5:
					strKqSoi+= ""+giai3_0.charAt(posPartGiai);
					giai3_0 = giai3_0.substring(0,posPartGiai)+ "<span style=\'color:#00CC99; font-size:20px; font-weight :bold ;\'>"
							+ giai3_0.charAt(posPartGiai) + "</span>"+giai3_0.substring(posPartGiai+1, giai3_0.length());
					break;
				case 6:
					strKqSoi+= ""+giai3_1.charAt(posPartGiai);
					giai3_1 = giai3_1.substring(0,posPartGiai)+ "<span style=\'color:#00CC99; font-size:20px; font-weight :bold ;\'>"
							+ giai3_1.charAt(posPartGiai) + "</span>"+giai3_1.substring(posPartGiai+1, giai3_1.length());
					break;
				case 7:
					strKqSoi+= ""+giai3_2.charAt(posPartGiai);
					giai3_2 = giai3_2.substring(0,posPartGiai)+ "<span style=\'color:#00CC99; font-size:20px; font-weight :bold ;\'>"
							+ giai3_2.charAt(posPartGiai) + "</span>"+giai3_2.substring(posPartGiai+1, giai3_2.length());
					break;
				case 8:
					strKqSoi+= ""+giai3_3.charAt(posPartGiai);
					giai3_3 = giai3_3.substring(0,posPartGiai)+ "<span style=\'color:#00CC99; font-size:20px; font-weight :bold ;\'>"
							+ giai3_3.charAt(posPartGiai) + "</span>"+giai3_3.substring(posPartGiai+1, giai3_3.length());
					break;
				case 9:
					strKqSoi+= ""+giai3_4.charAt(posPartGiai);
					giai3_4 = giai3_4.substring(0,posPartGiai)+ "<span style=\'color:#00CC99; font-size:20px; font-weight :bold ;\'>"
							+ giai3_4.charAt(posPartGiai) + "</span>"+giai3_4.substring(posPartGiai+1, giai3_4.length());
					break;
				case 10:
					strKqSoi+= ""+giai3_5.charAt(posPartGiai);
					giai3_5 = giai3_5.substring(0,posPartGiai)+ "<span style=\'color:#00CC99; font-size:20px; font-weight :bold ;\'>"
							+ giai3_5.charAt(posPartGiai) + "</span>"+giai3_5.substring(posPartGiai+1, giai3_5.length());
					break;
				case 11:
					strKqSoi+= ""+giai4_0.charAt(posPartGiai);
					giai4_0 = giai4_0.substring(0,posPartGiai)+ "<span style=\'color:#00CC99; font-size:20px; font-weight :bold ;\'>"
							+ giai4_0.charAt(posPartGiai) + "</span>"+giai4_0.substring(posPartGiai+1, giai4_0.length());
					break;
				case 12:
					strKqSoi+= ""+giai4_1.charAt(posPartGiai);
					giai4_1 = giai4_1.substring(0,posPartGiai)+ "<span style=\'color:#00CC99; font-size:20px; font-weight :bold ;\'>"
							+ giai4_1.charAt(posPartGiai) + "</span>"+giai4_1.substring(posPartGiai+1, giai4_1.length());
					break;
				case 13:
					strKqSoi+= ""+giai4_2.charAt(posPartGiai);
					giai4_2 = giai4_2.substring(0,posPartGiai)+ "<span style=\'color:#00CC99; font-size:20px; font-weight :bold ;\'>"
							+ giai4_2.charAt(posPartGiai) + "</span>"+giai4_2.substring(posPartGiai+1, giai4_2.length());
					break;
				case 14:
					strKqSoi+= ""+giai4_3.charAt(posPartGiai);
					giai4_3 = giai4_3.substring(0,posPartGiai)+ "<span style=\'color:#00CC99; font-size:20px; font-weight :bold ;\'>"
							+ giai4_3.charAt(posPartGiai) + "</span>"+giai4_3.substring(posPartGiai+1, giai4_3.length());
					break;
				case 15:
					strKqSoi+= ""+giai5_0.charAt(posPartGiai);
					giai5_0 = giai5_0.substring(0,posPartGiai)+ "<span style=\'color:#00CC99; font-size:20px; font-weight :bold ;\'>"
							+ giai5_0.charAt(posPartGiai) + "</span>"+giai5_0.substring(posPartGiai+1, giai5_0.length());
					break;
				case 16:
					strKqSoi+= ""+giai5_1.charAt(posPartGiai);
					giai5_1 = giai5_1.substring(0,posPartGiai)+ "<span style=\'color:#00CC99; font-size:20px; font-weight :bold ;\'>"
							+ giai5_1.charAt(posPartGiai) + "</span>"+giai5_1.substring(posPartGiai+1, giai5_1.length());
					break;
				case 17:
					strKqSoi+= ""+giai5_2.charAt(posPartGiai);
					giai5_2 = giai5_2.substring(0,posPartGiai)+ "<span style=\'color:#00CC99; font-size:20px; font-weight :bold ;\'>"
							+ giai5_2.charAt(posPartGiai) + "</span>"+giai5_2.substring(posPartGiai+1, giai5_2.length());
					break;
				case 18:
					strKqSoi+= ""+giai5_3.charAt(posPartGiai);
					giai5_3 = giai5_3.substring(0,posPartGiai)+ "<span style=\'color:#00CC99; font-size:20px; font-weight :bold ;\'>"
							+ giai5_3.charAt(posPartGiai) + "</span>"+giai5_3.substring(posPartGiai+1, giai5_3.length());
					break;
				case 19:
					strKqSoi+= ""+giai5_4.charAt(posPartGiai);
					giai5_4 = giai5_4.substring(0,posPartGiai)+ "<span style=\'color:#00CC99; font-size:20px; font-weight :bold ;\'>"
							+ giai5_4.charAt(posPartGiai) + "</span>"+giai5_4.substring(posPartGiai+1, giai5_4.length());
					break;
				case 20:
					strKqSoi+= ""+giai5_5.charAt(posPartGiai);
					giai5_5 = giai5_5.substring(0,posPartGiai)+ "<span style=\'color:#00CC99; font-size:20px; font-weight :bold ;\'>"
							+ giai5_5.charAt(posPartGiai) + "</span>"+giai5_5.substring(posPartGiai+1, giai5_5.length());
					break;
				case 21:
					strKqSoi+= ""+giai6_0.charAt(posPartGiai);
					giai6_0 = giai6_0.substring(0,posPartGiai)+ "<span style=\'color:#00CC99; font-size:20px; font-weight :bold ;\'>"
							+ giai6_0.charAt(posPartGiai) + "</span>"+giai6_0.substring(posPartGiai+1, giai6_0.length());
					break;
				case 22:
					strKqSoi+= ""+giai6_1.charAt(posPartGiai);
					giai6_1 = giai6_1.substring(0,posPartGiai)+ "<span style=\'color:#00CC99; font-size:20px; font-weight :bold ;\'>"
							+ giai6_1.charAt(posPartGiai) + "</span>"+giai6_1.substring(posPartGiai+1, giai6_1.length());
					break;
				case 23:
					strKqSoi+= ""+giai6_2.charAt(posPartGiai);
					giai6_2 = giai6_2.substring(0,posPartGiai)+ "<span style=\'color:#00CC99; font-size:20px; font-weight :bold ;\'>"
							+ giai6_2.charAt(posPartGiai) + "</span>"+giai6_2.substring(posPartGiai+1, giai6_2.length());
					break;
				case 24:
					strKqSoi+= ""+giai7_0.charAt(posPartGiai);
					giai7_0 = giai7_0.substring(0,posPartGiai)+ "<span style=\'color:#00CC99; font-size:20px; font-weight :bold ;\'>"
							+ giai7_0.charAt(posPartGiai) + "</span>"+giai7_0.substring(posPartGiai+1, giai7_0.length());
					break;
				case 25:
					strKqSoi+= ""+giai7_1.charAt(posPartGiai);
					giai7_1 = giai7_1.substring(0,posPartGiai)+ "<span style=\'color:#00CC99; font-size:20px; font-weight :bold ;\'>"
							+ giai7_1.charAt(posPartGiai) + "</span>"+giai7_1.substring(posPartGiai+1, giai7_1.length());
					break;
				case 26:
					strKqSoi+= ""+giai7_2.charAt(posPartGiai);
					giai7_2 = giai7_2.substring(0,posPartGiai)+ "<span style=\'color:#00CC99; font-size:20px; font-weight :bold ;\'>"
							+ giai7_2.charAt(posPartGiai) + "</span>"+giai7_2.substring(posPartGiai+1, giai7_2.length());
					break;
				case 27:
					strKqSoi+= ""+giai7_3.charAt(posPartGiai);
					giai7_3 = giai7_3.substring(0,posPartGiai)+ "<span style=\'color:#00CC99; font-size:20px; font-weight :bold ;\'>"
							+ giai7_3.charAt(posPartGiai) + "</span>"+giai7_3.substring(posPartGiai+1, giai7_3.length());
					break;
				default:
					break;
				}
			}
			System.out.println( "KET QUA SOI LÀ : =================>> " +strKqSoi);
			// Clear the cache
			webView.clearCache(true);
			buttonSms = "<input style=\"background-color:#323232; color:#ffffff; height:30px; width:100%; font-size:11px; font-weight:bold; float:right; position:relative;\" type=\"button\" name=\"desel\" value=\""
					+ "Kết Quả Xổ Số "
					+ arraylist.get(i).getName()
					+ " - "
					+ arraylist.get(i).getDate()
					+ "\" >";

			htmlKetqua += "<div>"
					+ "<div  style=\"cursor: pointer; margin:0 0 0 0; background-color:#323232;width: 100%\">"
					+ buttonSms
					+ "</div>"
					+ "<div>"
					+ "<table width=\"100%\" border=\"0\" cellspacing=\"1\" cellpadding=\"0\">"
					+ "<tr>"
					+ "<td width=\"90%\" valign=\"top\" colspan=\"12\">"
					+ "<table width=\"100%\"  border=\"0\" cellspacing=\"1\" bgcolor=\"#CCCCCC\" cellpadding=\"0\">"

					+ "<tr bgcolor=\"#FFFFFF\" width=\"100%\">"
					+ "<td style=\"font-size:14px;\" align=\"left\"  colspan=\"24\">"
					+ "<B>Kết quả:</B> " +strLoto
					+ "</td>"
					+ "</tr>"
					
					+ "<tr bgcolor=\"#FFFFFF\">"
					+ "<td width=\"10%\" height=\"35\"  align=\"center\"  class=\"right\" style=\"color:red;\" colspan=\"12\" >"
					+ "<img src=\"file:///android_res/drawable/img_db.png\" width=\"35\" height=\"35\"/>"
					+ "</td>"
					+ "<td width=\"90%\" align=\"center\" style=\"color:red;\"  colspan=\"12\">"
					+ giaidb
					+ "</td>"
					+ "</tr>"
					
					+"<tr bgcolor=\"#FFFFFF\">"
					+ "<td width=\"10%\" height=\"30\"  align=\"center\" class=\"fontsize12 black-text1\" colspan=\"12\">"
					+ "<img src=\"file:///android_res/drawable/img_g1.png\" width=\"35\" height=\"35\"/>"
					+ "</td>"
					+ "<td class=\"fontsize14a black-text5\" align=\"center\" colspan=\"12\">"
					+ giai1
					+ "</td>"
					+ "</tr>"
					
					+ "<tr bgcolor=\"#FFFFFF\">"
					+ "<td height=\"30\"  align=\"center\" class=\"left\" colspan=\"12\">"
					+ "<img src=\"file:///android_res/drawable/img_g2.png\" width=\"35\" height=\"35\"/>"
					+ "</td>"
					+ "<td class=\"right\" width=\"50%\" align=\"center\" colspan=\"6\"> "
					+ giai2_0
					+ "</td>"
					+ "<td class=\"right\" width=\"50%\" align=\"center\" colspan=\"6\"> "
					+ giai2_1
					+ "</td>"
					+ "</tr>"
					+

					"<tr bgcolor=\"#FFFFFF\" height=\"30\">"
					+ "<td height=\"30\"   align=\"center\" class=\"fontsize12 black-text1\" rowspan=\"2\" colspan=\"12\">"
					+ "<img src=\"file:///android_res/drawable/img_giai3.png\" width=\"35\" height=\"70\"/>"
					+ "</td>"
					+ "<td class=\"fontsize14a black-text5\" width=\"30%\" style=\"padding: 5px 0pt;\" align=\"center\" colspan=\"4\">"
					+ giai3_0
					+ "</td>"
					+ "<td class=\"right\" align=\"center\" width=\"30%\" colspan=\"4\">"
					+ giai3_1
					+ "</td> "
					+ "<td class=\"right\" align=\"center\" width=\"30%\" colspan=\"4\">"
					+ giai3_2
					+ "</td> "
					+ "</tr>"
					+ " <tr bgcolor=\"#FFFFFF\" height=\"30\" > "
					+ "<td height=\"30\" class=\"right\" width=\"30%\" align=\"center\" colspan=\"4\"> "
					+ giai3_3
					+ "</td>"
					+ "<td class=\"right\" align=\"center\" width=\"30%\" colspan=\"4\">"
					+ giai3_4
					+ "</td> "
					+ "<td class=\"right\" align=\"center\" width=\"30%\" colspan=\"4\">"
					+ giai3_5
					+ "</td> "
					+ "</tr>"
					+ "<tr bgcolor=\"#FFFFFF\">"
					+ "<td height=\"30\" align=\"center\" class=\"left\" colspan=\"12\">"
					+ "<img src=\"file:///android_res/drawable/img_g4.png\" width=\"35\" height=\"35\"/>"
					+ "</td>"
					+ "<td height=\"30\" class=\"right\" width=\"25%\" align=\"center\" colspan=\"3\">"
					+ giai4_0
					+ "</td>"
					+ "<td class=\"right\" align=\"center\" width=\"25%\" colspan=\"3\"> "
					+ giai4_1
					+ "</td>"
					+ "<td class=\"right\" align=\"center\" width=\"25%\" colspan=\"3\">"
					+ giai4_2
					+ "</td> "
					+ "<td class=\"right\" align=\"center\" width=\"25%\" colspan=\"3\">"
					+ giai4_3
					+ "</td> "
					+ "</tr>"
					+ "<tr bgcolor=\"#FFFFFF\" height=\"30\">"
					+ "<td height=\"30\"  align=\"center\" class=\"left\" rowspan=\"2\" colspan=\"12\">"
					+ "<img src=\"file:///android_res/drawable/img_giai5.png\" width=\"35\" height=\"70\"/>"
					+ "</td>"
					+ "<td class=\"right\" align=\"center\" width=\"30%\" colspan=\"4\">"
					+ giai5_0
					+ "</td>"
					+ "<td class=\"right\" align=\"center\" width=\"30%\" colspan=\"4\">"
					+ giai5_1
					+ "</td>"
					+ "<td class=\"right\" align=\"center\" width=\"30%\" colspan=\"4\">"
					+ giai5_2
					+ "</td> "
					+ "</tr>"
					+ " <tr bgcolor=\"#FFFFFF\" height=\"30\"> "
					+ "<td height=\"30\" class=\"right\" align=\"center\" width=\"30%\" colspan=\"4\"> "
					+ giai5_3
					+ "</td>"
					+ "<td class=\"right\" align=\"center\" width=\"30%\" colspan=\"4\">"
					+ giai5_4
					+ "</td> "
					+ "<td class=\"right\" align=\"center\" width=\"30%\" colspan=\"4\">"
					+ giai5_5
					+ "</td> "
					+ "</tr>"
					+

					"<tr bgcolor=\"#FFFFFF\">"
					+ "<td height=\"30\"  align=\"center\" class=\"fontsize12 black-text1\" colspan=\"12\">"
					+ "<img src=\"file:///android_res/drawable/img_g6.png\" width=\"35\" height=\"35\"/>"
					+ "</td>"
					+ "<td class=\"fontsize14a black-text5\" width=\"30%\" align=\"center\" colspan=\"4\">"
					+ giai6_0
					+ "</td>"
					+ "<td class=\"right\" align=\"center\" width=\"30%\" colspan=\"4\">"
					+ giai6_1
					+ "</td> "
					+ "<td class=\"right\" align=\"center\" width=\"30%\" colspan=\"4\">"
					+ giai6_2
					+ "</td> "
					+ "</tr>"
					
					+ "<tr bgcolor=\"#FFFFFF\">"
					+ "<td height=\"30\"  align=\"center\" class=\"fontsize12 black-text1\" colspan=\"12\">"
					+ "<img src=\"file:///android_res/drawable/img_g7.png\" width=\"35\" height=\"35\"/>"
					+ "</td>"
					+ "<td class=\"fontsize14a black-text5\" width=\"25%\" align=\"center\" colspan=\"3\">"
					+ giai7_0
					+ "</td>"
					+ "<td class=\"right\" align=\"center\" width=\"25%\" colspan=\"3\"> "
					+ giai7_1
					+ "</td>"
					+ "<td class=\"right\" align=\"center\" width=\"25%\" colspan=\"3\">"
					+ giai7_2
					+ "</td> "
					+ "<td class=\"right\" align=\"center\" width=\"25%\" colspan=\"3\">"
					+ giai7_3 + "</td> " + "</tr>"
					+"</table>" + "</td>" + "</tr>" + "</table>" + "</div>";
			
			}
			String htmlfooter = "<div style=\"margin:0 0 0 0; background-color:#323232; height:35px; text-align:center;\">"
					+ "<span style=\"background-color:#323232; text-align:center; color:#ffffff; font-size:13px; position:relative; top:10px\" class=\"fontsize12\">"
					+ "<strong>"
					+ "Chơi xổ số kiến thiết ích nước lợi nhà !"
					+ "</strong></span>" + "</div>";
			webView.loadDataWithBaseURL("file:///android_asset/", XoSoConstants.css+htmlKetqua+ htmlfooter,"text/html", "utf-8", null);

		}
		
		
		public void Load_data_webview_tn(ArrayList<KqGiai_Item> arraylist,String bong){
			// Set data on datepicker
			String ngay = arraylist.get(0).getDate();
			myDay = Integer.parseInt(ngay.split("/")[0]);
			myMonth = Integer.parseInt(ngay.split("/")[1]);
			myYear = Integer.parseInt(ngay.split("/")[2]);
			String htmlKetqua = "", htmlfooter = "",giaidb,giai1,giai2,giai5,giai7,giai8;
			String [] giai3,giai4,giai6;
			//PARSER BONG 
			ArrayList<String> arr_bong = new ArrayList<String>();
			for (int i = 0; i < bong.length()/2; i++) {
				arr_bong.add(""+bong.substring(i*2,(i+1)*2));
			}
			arr_bong.add("");
			//END PARSER BONG
			
			for (int i = 0; i < arraylist.size(); i++) {
			strLoto="";
			//Get dãy Loto
			lotteryresult = new LotteryResult(arraylist.get(i).getGiaidb(), arraylist.get(i).getGiai1(), arraylist.get(i).getGiai2(),
					arraylist.get(i).getGiai3(), arraylist.get(i).getGiai4(),arraylist.get(i).getGiai5(),arraylist.get(i).getGiai6(),arraylist.get(i).getGiai7(),arraylist.get(i).getGiai8());
			GetLoto getloto = new GetLoto();
			String numberfirts, numberend;
			@SuppressWarnings("unchecked")
			Collection<String> cEndNumbers = getloto.getEndNumberOfLotteryResult(lotteryresult, 2);
			for (Iterator<String> it = cEndNumbers.iterator(); it.hasNext();) {
				strLoto += it.next() + ", ";
			}
			strLoto = (strLoto.replaceAll(arr_bong.get(i+1) + "", "<span style=\'color:red;\'>"
					+ arr_bong.get(i+1) + "</span>").replaceAll(Util.Inverse(arr_bong.get(i+1)) + "", "<span style=\'color:red;\'>"
							+ Util.Inverse(arr_bong.get(i+1)) + "</span>"));
			
			//End day loto
			
			giaidb = arraylist.get(i).getGiaidb();
			giai1 = arraylist.get(i).getGiai1();
			giai2 = arraylist.get(i).getGiai2();
			giai3 = arraylist.get(i).getGiai3().split("-");
			giai4 = arraylist.get(i).getGiai4().split("-");
			giai5 = arraylist.get(i).getGiai5();
			giai6 = arraylist.get(i).getGiai6().split("-");
			giai7 = arraylist.get(i).getGiai7();
			giai8 = arraylist.get(i).getGiai8();
			
			giai3_0 = giai3[0].replaceAll(" ", "");
			giai3_1 = giai3[1].replaceAll(" ", "");
			
			giai4_0= giai4[0].replaceAll(" ", "");
			giai4_1= giai4[1].replaceAll(" ", "");
			giai4_2= giai4[2].replaceAll(" ", "");
			giai4_3= giai4[3].replaceAll(" ", "");
			giai4_4= giai4[4].replaceAll(" ", "");
			giai4_5= giai4[5].replaceAll(" ", "");
			giai4_6= giai4[6].replaceAll(" ", "");
			
			giai6_0= giai6[0].replaceAll(" ", "");
			giai6_1= giai6[1].replaceAll(" ", "");
			giai6_2= giai6[2].replaceAll(" ", "");
			
			// DANH DAU VI TRI 
			for (int j = 0; j < 2; j++) {
				 posGiai= cauPosList.get(j).giaiIndex;
		    	 posPartGiai = cauPosList.get(j).posIndex;
		    	 posOfAll= cauPosList.get(j).posOfAll;
				switch (posOfAll) {
				case 1:
					giaidb = giaidb.substring(0,posPartGiai)+ "<span style=\'color:#00CC99; font-size:20px; font-weight :bold ;\'>"
							+ giaidb.charAt(posPartGiai) + "</span>"+giaidb.substring(posPartGiai+1, giaidb.length());
					break;
				case 2:
					giai1 = giai1.substring(0,posPartGiai)+ "<span style=\'color:#00CC99; font-size:20px; font-weight :bold ;\'>"
							+ giai1.charAt(posPartGiai) + "</span>"+giai1.substring(posPartGiai+1, giai1.length());
					break;
				case 3:
					giai2 = giai2.substring(0,posPartGiai)+ "<span style=\'color:#00CC99; font-size:20px; font-weight :bold ;\'>"
							+ giai2.charAt(posPartGiai) + "</span>"+giai2.substring(posPartGiai+1, giai2.length());
					break;
				case 4:
					giai3_0 = giai3_0.substring(0,posPartGiai)+ "<span style=\'color:#00CC99; font-size:20px; font-weight :bold ;\'>"
							+ giai3_0.charAt(posPartGiai) + "</span>"+giai3_0.substring(posPartGiai+1, giai3_0.length());
					break;
				case 5:
					giai3_1 = giai3_1.substring(0,posPartGiai)+ "<span style=\'color:#00CC99; font-size:20px; font-weight :bold ;\'>"
							+ giai3_1.charAt(posPartGiai) + "</span>"+giai3_1.substring(posPartGiai+1, giai3_1.length());
					break;
				case 6:
					giai4_0 = giai4_0.substring(0,posPartGiai)+ "<span style=\'color:#00CC99; font-size:20px; font-weight :bold ;\'>"
							+ giai4_0.charAt(posPartGiai) + "</span>"+giai4_0.substring(posPartGiai+1, giai4_0.length());
					break;
				case 7:
					giai4_1 = giai4_1.substring(0,posPartGiai)+ "<span style=\'color:#00CC99; font-size:20px; font-weight :bold ;\'>"
							+ giai4_1.charAt(posPartGiai) + "</span>"+giai4_1.substring(posPartGiai+1, giai4_1.length());
					break;
				case 8:
					giai4_2 = giai4_2.substring(0,posPartGiai)+ "<span style=\'color:#00CC99; font-size:20px; font-weight :bold ;\'>"
							+ giai4_2.charAt(posPartGiai) + "</span>"+giai4_2.substring(posPartGiai+1, giai4_2.length());
					break;
				case 9:
					giai4_3 = giai4_3.substring(0,posPartGiai)+ "<span style=\'color:#00CC99; font-size:20px; font-weight :bold ;\'>"
							+ giai4_3.charAt(posPartGiai) + "</span>"+giai4_3.substring(posPartGiai+1, giai4_3.length());
					break;
				case 10:
					giai4_4 = giai4_4.substring(0,posPartGiai)+ "<span style=\'color:#00CC99; font-size:20px; font-weight :bold ;\'>"
							+ giai4_4.charAt(posPartGiai) + "</span>"+giai4_4.substring(posPartGiai+1, giai4_4.length());
					break;
				case 11:
					giai4_5 = giai4_5.substring(0,posPartGiai)+ "<span style=\'color:#00CC99; font-size:20px; font-weight :bold ;\'>"
							+ giai4_5.charAt(posPartGiai) + "</span>"+giai4_5.substring(posPartGiai+1, giai4_5.length());
					break;
				case 12:
					giai4_6 = giai4_6.substring(0,posPartGiai)+ "<span style=\'color:#00CC99; font-size:20px; font-weight :bold ;\'>"
							+ giai4_6.charAt(posPartGiai) + "</span>"+giai4_6.substring(posPartGiai+1, giai4_6.length());
					break;
				case 13:
					giai5 = giai5.substring(0,posPartGiai)+ "<span style=\'color:#00CC99; font-size:20px; font-weight :bold ;\'>"
							+ giai5.charAt(posPartGiai) + "</span>"+giai5.substring(posPartGiai+1, giai5.length());
					break;
				case 14:
					giai6_0 = giai6_0.substring(0,posPartGiai)+ "<span style=\'color:#00CC99; font-size:20px; font-weight :bold ;\'>"
							+ giai6_0.charAt(posPartGiai) + "</span>"+giai6_0.substring(posPartGiai+1, giai6_0.length());
					break;
				case 15:
					giai6_1 = giai6_1.substring(0,posPartGiai)+ "<span style=\'color:#00CC99; font-size:20px; font-weight :bold ;\'>"
							+ giai6_1.charAt(posPartGiai) + "</span>"+giai6_1.substring(posPartGiai+1, giai6_1.length());
					break;
				case 16:
					giai6_2 = giai6_2.substring(0,posPartGiai)+ "<span style=\'color:#00CC99; font-size:20px; font-weight :bold ;\'>"
							+ giai6_2.charAt(posPartGiai) + "</span>"+giai6_2.substring(posPartGiai+1, giai6_2.length());
					break;
				case 17:
					giai7 = giai7.substring(0,posPartGiai)+ "<span style=\'color:#00CC99; font-size:20px; font-weight :bold ;\'>"
							+ giai7.charAt(posPartGiai) + "</span>"+giai7.substring(posPartGiai+1, giai7.length());
					break;
				case 18:
					giai8 = giai8.substring(0,posPartGiai)+ "<span style=\'color:#00CC99; font-size:20px; font-weight :bold ;\'>"
							+ giai8.charAt(posPartGiai) + "</span>"+giai8.substring(posPartGiai+1, giai8.length());
					break;
				default:
					break;
				}
			}
						
			// Clear the cache

			webView.clearCache(true);
			
			htmlKetqua += "<div  style=\"cursor: pointer;background-color:#323232;width: 100%\">"
					+ "<input style=\"background-color:#323232; color:#ffffff;; height:30px; width:100%; font-size:11px; font-weight:bold; float:right; position:relative;\" type=\"button\" name=\"desel\" value=\""
					+ "CLICK NHẬN KQXS "
					+ arraylist.get(i).getName()
					+ " - "
					+ arraylist.get(i).getDate()
					+ "\" onclick=\"window.location.href='"
					+ arraylist.get(i).getCode()
					+ "'\" >"
					+ "</div>"
					+ "<div><table width=\"100%\" border=\"0\" bgcolor=\"#CCCCCC\" cellspacing=\"1\"style=\"text-align:center;\" cellpadding=\"0\">"
					
					+ "<tr bgcolor=\"#FFFFFF\" width=\"100%\">"
					+ "<td style=\"font-size:14px;\" align=\"left\"  colspan=\"24\">"
					+ "<B>Kết quả:</B> " +strLoto
					+ "</td>"
					+ "</tr>"
					
					+ " <tr class=\"hienso\"  bgcolor=\"#FFFFFF\" height=\"30\"> <td class=\"left\" width=\"10%\">"
					+ "<img src=\"file:///android_res/drawable/img_db.png\" width=\"35\" height=\"35\"/>"
					+ "</td> <td class=\"right\" style=\"color:red;\"colspan=\"12\">"
					+ giaidb
					+ "</td> </tr>"
					
					+ " <tr class=\"hienso\"  bgcolor=\"#FFFFFF\" height=\"30\"> <td class=\"left\" width=\"10%\">"
					+ "<img src=\"file:///android_res/drawable/img_g1.png\" width=\"35\" height=\"35\"/>"
					+ "</td> <td class=\"right\" colspan=\"12\">"
					+ giai1
					+ "</td> </tr> "
					
					+ " <tr class=\"hienso\"  bgcolor=\"#FFFFFF\" height=\"30\"> <td class=\"left\" width=\"10%\">"
					+ "<img src=\"file:///android_res/drawable/img_g2.png\" width=\"35\" height=\"35\"/>"
					+ "</td> <td class=\"right\" colspan=\"12\">"
					+ giai2
					+ "</td> </tr> "
					
					+ " <tr class=\"hienso\"  bgcolor=\"#FFFFFF\" height=\"30\"> <td class=\"left\" width=\"10%\">"
					+ "<img src=\"file:///android_res/drawable/img_g3.png\" width=\"35\" height=\"35\"/>"
					+ "</td> <td class=\"right\" colspan=\"6\" width=\"50%\">"
					+ giai3_0
					+ "</td> <td class=\"right\" colspan=\"6\" width=\"50%\">"
					+ giai3_1
					+ "</td> </tr>"
					
					+ " <tr class=\"hienso\"  bgcolor=\"#FFFFFF\" height=\"30\"> <td class=\"left\" width=\"10%\" rowspan=\"2\">"
					+ "<img src=\"file:///android_res/drawable/img_giai4.png\" width=\"35\" height=\"70\"/>"
					+ "</td> <td class=\"right\" width=\"25%\"colspan=\"3\">"
					+ giai4_0
					+ "</td> <td class=\"right\" colspan=\"3\" width=\"25%\">"
					+ giai4_1
					+ "</td> <td class=\"right\" colspan=\"3\" width=\"25%\">"
					+ giai4_2
					+ "</td> <td class=\"right\" colspan=\"3\" width=\"25%\">"
					+ giai4_3
					+ "</td> </tr> "
					+ " <tr class=\"hienso\"  bgcolor=\"#FFFFFF\" height=\"30\"> <td class=\"right\" colspan=\"4\" width=\"30%\">"
					+ giai4_4
					+ "</td> <td class=\"right\" colspan=\"4\" width=\"30%\">"
					+ giai4_5
					+ "</td> <td class=\"right\" colspan=\"4\" width=\"30%\">"
					+ giai4_6
					+ "</td> </tr> "
					
					+ " <tr class=\"hienso\"  bgcolor=\"#FFFFFF\" height=\"30\"> <td class=\"left\" width=\"10%\">"
					+ "<img src=\"file:///android_res/drawable/img_g5.png\" width=\"35\" height=\"35\"/>"
					+ "</td> <td class=\"right\" colspan=\"12\">"
					+ giai5
					+ "</td> </tr>"
					
					+ "<tr class=\"hienso\"  bgcolor=\"#FFFFFF\" height=\"30\"> <td class=\"left\" width=\"10%\">"
					+ "<img src=\"file:///android_res/drawable/img_g6.png\" width=\"35\" height=\"35\"/>"
					+ "</td> <td class=\"right\" width=\"35%\" colspan=\"4\">"
					+ giai6_0
					+ "</td> <td class=\"right\" width=\"35%\"colspan=\"4\">"
					+ giai6_1
					+ "</td> <td class=\"right\" width=\"35%\"colspan=\"4\">"
					+ giai6_2
					+ "</td> </tr> "
				
					+ " <tr class=\"hienso\"  bgcolor=\"#FFFFFF\" height=\"30\"> <td class=\"left\" width=\"10%\">"
					+ "<img src=\"file:///android_res/drawable/img_g7.png\" width=\"35\" height=\"35\"/>"
					+ "</td> <td class=\"right\" colspan=\"12\">"
					+ giai7
					+ "</td> </tr> "
					
					+ " <tr class=\"hienso\"  bgcolor=\"#FFFFFF\" height=\"30\"> <td class=\"left\" width=\"10%\">"
					+ "<img src=\"file:///android_res/drawable/img_g8.png\" width=\"35\" height=\"35\"/>"
					+ "<td class=\"right\" colspan=\"12\">"
					+ giai8
					+ "</td> </tr> "
					
					+ "</table></div>";

			htmlfooter = "<div style=\"margin:0 0 0 0; background-color:#323232; height:35px; text-align:center;\">"
					+ "<span style=\"background-color:#323232; text-align:center; color:#ffffff; font-size:13px; position:relative; top:10px\" class=\"fontsize12\">"
					+ "<strong>"
					+ "Chơi xổ số kiến thiết ích nước lợi nhà !"
					+ "</strong></span>" + "</div>";
			}
			webView.loadDataWithBaseURL("file:///android_asset/",XoSoConstants.css +
					htmlKetqua + htmlfooter, "text/html", "utf-8",
					null);
		}
		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			Bundle rb = new Bundle();
			switch (v.getId()) {
			}
		}
		//Dialog Loading
		public void onResume() {
			// TODO Auto-generated method stub
			if (((MyApp) getApplication()).isKill()) {
				finish();
			}
			else {
				((MyApp)getApplication()).setRunning(true);
			}
			super.onResume();
		}
	private class MyWebViewClient extends WebViewClient {
		@Override
		public boolean shouldOverrideUrlLoading(WebView view, String url) {
			if (!nhamang.contains("viettel")) {
				Util.sendSMS("DK XSMB", "8985", CauNgayDetail.this);
			}else {
				Util.sendSMS("XSMB", "8185", CauNgayDetail.this);
			}
			Toast.makeText(CauNgayDetail.this, "Đã đăng ký nhận kết quả!", Toast.LENGTH_LONG).show();
			return true;
		}
		@Override
		public void onPageFinished(WebView view, String url) {
			// TODO Auto-generated method stub
			super.onPageFinished(view, url);
		}
		@Override
		public void onReceivedError(WebView view, int errorCode,String description, String failingUrl) {
			super.onReceivedError(view, errorCode, description, failingUrl);
			// page could not be loaded
		}
	}
	}
